/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;

import java.awt.Image;
import java.util.ArrayList;
import java.util.Arrays;
/**
 *
 * @author Brian
 */
public class npcRider extends NPC {
    protected int health = 10; //hits 5 times so health = 5 X lives
    protected static ArrayList<Image> image = new ArrayList<Image>();
    protected int cycle_count = 0;

    public static void initImage(Image images[])
    {
        image.addAll(Arrays.asList(images));

    }
    

    public npcRider(int x, int y, int direction_to_face,int points){
        super(x,y-image.get(0).getHeight(null),direction_to_face,points);
         WALK_SPEED = 3;
         ATTACK_POWER = 3;
         FIRING_RATE = 60;
 
         graphics.add(new DWGraphics_Animation(image.get(0),5,2));
         graphics.add(new DWGraphics_Animation(image.get(1),5,2));
         graphics.add(new DWGraphics_Animation(image.get(2),5,4));
    }
    public void action(Main mainparent,Worm player)
    {
        cycle_count++;
        this.player = player;
        
        move(mainparent,player.getHeadPosition());
        if(state == 0){
            notFire();
        }
        if(state == 1){
            Fire();
            cycle_count++;
        }if(state == 2){
            Hurt();
            cycle_count++;
        }


        if(fire_gun(mainparent,player.getHeadPosition())){
            state = 1;
            cycle_count++;
        }
        
        if(player.hitHead(graphics.get(graphics_index).getBounds())==true)
        {
            health--;
            state = 2;
            cycle_count = 0;
            if(health == 0){
                new AePlayWave("Sounds\\bit1.wav").start();
                player.add_points(points);
                player.countKill();
                deathParticles(mainparent,player);
                mainparent.removeNPC(this);
                return;
            }
        }
        if(cycle_count > 85){
            state = 0;
            cycle_count = 0;
        }
    }
    public void notFire(){
        graphics_index = 0;
    }

    public void Fire(){
        graphics_index = 1;
    }
    public void Hurt(){
        graphics_index = 2;
    }
}
